package com.skt.common_hr.appmsnreq.model
{
	import com.skt.common_hr.appmsnreq.model.vo.voAppmMain;
	import com.skt.common_hr.common.approval.IRequestApprovalProxy;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.collections.ArrayCollection;

	public class AppmsnreqApprovalProxy extends CommonProxy implements IRequestApprovalProxy
	{
		public static const NAME:String = "AppmsnreqApprovalProxy";
		public var dataProvider:ArrayCollection;

		private var _bAppType:Boolean = false;		// 정산 포함여부
		private var _amount:Number;

		public var dpObj:Object;

		private var templateHTML1:String = "";
		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function AppmsnreqApprovalProxy(data:Object=null)
		{
			super(NAME, data);
			loadTemplate1();
		}

		private var _key:String = "";
		public function get key():String
		{
			return _key;
		}
		public function set key(k:String):void
		{
			_key = k;
		}

		public function get title():String
		{
			var tmp:String;
			tmp = "이동발령요청(";
			tmp += dpObj.APPDT;
			tmp += ")";
			return tmp;
		}



		public function get content():String
		{
			return buildHTML();
		}

		public function get appCode():String
		{
			return "19"; 	//
		}

 		private function loadTemplate1():void
		{
			var loader:URLLoader = new URLLoader();
			var request:URLRequest = new URLRequest("assets/template/appmsnreq.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}


		private function templateResult(event:Event):void
		{
			templateHTML1 = event.target.data;
		}



		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("ioErrorHandler: " + event);
		}


		private function buildHTML():String
		{
			var htmlAll:String = templateHTML1;
			var htmlBlock:String = "";

			var ptnSDATE:RegExp  		= /__SDATE__/;
			var ptnMemberBlock:RegExp = /__MEMBERS__/;

			htmlAll = htmlAll.replace(ptnSDATE				, dpObj.APPDT);
			htmlAll = htmlAll.replace(ptnMemberBlock		, buildMemberBlock());
			return htmlAll;
		}
		
		private function buildMemberBlock():String
		{
			var blocks:String = "";
			var openColumn:String = "<TD style='background: #fdfdf3; text-align: center; font-size: 9pt; border-bottom-color : #000000; border-bottom-style : solid; border-bottom-width : 1px; border-right-color : #000000; border-right-style : solid;    border-right-width : 1px;' height=30><P>";
			
			for each(var vo:voAppmMain in dpObj.acMem) {
				blocks += "<TR>" + openColumn + vo.PERNR + "</P></TD>";
				blocks += openColumn + vo.ENAME + "</P></TD>";				
				blocks += openColumn + vo.PSTEXT + "</P></TD>";
				blocks += openColumn + vo.PPLSTX + "</P></TD>";
				blocks += openColumn + vo.ASTEXT + "</P></TD>";
				blocks += openColumn + vo.APLSTX + "</P></TD>";
				blocks += "</TR>";
			}
			return blocks
		}		
	}
}